package com.qf.web.listeners;

import com.qf.pojo.TbGoodsType;
import com.qf.service.GoodTypeService;
import com.qf.service.impl.GoodTypeServiceImpl;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

/**
 * Create by 周志豪 on 2022/8/20  21:45
 *
 * @authoe 周志豪
 * @veision 1.0
 * //TODO  想好了再去做
 * @since 1.0
 */
@WebListener
public class MyContextLoadListener implements ServletContextListener {

    private GoodTypeService goodTypeService = new GoodTypeServiceImpl();

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //将数据保存到servletcontext中
        List<TbGoodsType> goodsTypeList = goodTypeService.findAllFirstLevelType();
        sce.getServletContext().setAttribute("goodTypes", goodsTypeList);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        //在程序退出的时候删除context中的数据
        sce.getServletContext().removeAttribute("goodTypes");
    }
}
